let Mock = require('mockjs');
let Random = Mock.Random;

Date.prototype.Format = function (fmt) { //author: meizz 
  var o = {
    "M+": this.getMonth() + 1, //月份 
    "d+": this.getDate(), //日 
    "h+": this.getHours(), //小时 
    "m+": this.getMinutes(), //分 
    "s+": this.getSeconds(), //秒 
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
    "S": this.getMilliseconds() //毫秒 
  };
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  return fmt;
}

module.exports = function () {

  var data = {
    news: [],
    banners: [],
    comments: [],
    imageCategorys: [],
    images: [],
    goods: [],
    shopCars: []
  };

  // news
  for (var i = 0; i < 50; i++) {

    var content = Random.cparagraph(1, 10);

    data.news.push({
      id: i + 1,
      title: Random.ctitle(3, 20),
      desc: content.substr(0, 30),
      addtime: Random.datetime('yyyy-MM-dd HH:mm:ss'),
      tag: Random.csentence(1, 4),
      click: Random.integer(100, 5000),
      images: Random.image('500x500', Random.color(), Random.cword(2, 6)),
      content: Random.cparagraph(4, 10)
    })
  }

  // banners
  for (var i = 0; i < 5; i++) {
    data.banners.push({
      id: i,
      img: Random.image('414x200', Random.color(), Random.cword(2, 6)),
      url: Random.url('http', Random.domain())
    })
  }

  // comments
  for (var i = 0; i < 500; i++) {

    var content = Random.cparagraph(0, 10);

    data.comments.push({
      id: i + 1,
      artid: i % 50 + 1,
      desc: Random.csentence(),
      name: Random.cname(),
      addtime: Random.datetime('yyyy-MM-dd HH:mm:ss')
    })
  }

  // imageCategorys
  var categorys = ['明星写真', '性感美女', '实景拍摄', '古典美女', '游戏人物']
  for (var i = 0; i < 5; i++) {
    data.imageCategorys.push({
      id: i + 1,
      title: categorys[i]
    })
  }

  // images
  for (var i = 0; i < 50; i++) {
    data.images.push({
      id: i + 1,
      categoryid: Random.integer(1, 5),
      title: Random.ctitle(4, 20),
      desc: Random.cparagraph(1, 3),
      addtime: Random.datetime('yyyy-MM-dd HH:mm:ss'),
      click: Random.integer(1, 5000),
      imgs: GetImageList()
    })
  }

  // goods
  for (var i = 0; i < 70; i++) {
    data.goods.push({
      id: i+1,
      title: Random.ctitle(10,30),
      desc: Random.cparagraph(1,4),
      addtime: Random.datetime('yyyy-MM-dd HH:mm:ss'),
      count: Random.integer(10, 5000),
      img: '../../images/phone'+(i%7+1)+'.jpg',
      now: Random.integer(699, 999),
      old: Random.integer(999, 1299),
      imgs: GetImageList(),
      goodsnum: Random.guid().split('-')[0],
      content: Random.cparagraph(1, 2)+'<img src="../../images/phone'+(i%7+1)+'.jpg">'+Random.cparagraph(20, 30)
    })
  }

  // shopCars
  for(var i = 0;i<50;i++) {
    data.shopCars.push({
      id: i+1,
      count: Random.integer(1, 10),
      title: Random.ctitle(10,30),
      price: Random.integer(699, 999),
      img: '../../images/phone'+(i%7+1)+'.jpg'
    })
  }


  return data
}

function GetImageList() {
  var imgslist = []
  for (var j = 0; j < Random.integer(2, 7); j++) {
    imgslist.push(Random.image('414x500', Random.color(), Random.color(), '.png', Random.name()))
  }
  return imgslist
}
